package inter;

import symbols.Type;

public class Atribuicao extends Stmt {
	
	Id idVar;
	Expr exprAtr;
	
	public Atribuicao(Id idVar, Expr exprAtr) {
		super();
		this.idVar = idVar;
		this.exprAtr = exprAtr;
		if(check(idVar.type, exprAtr.type) == null) error("Erro de tipo na atribuicao");
	}
	
	public Type check(Type p1, Type p2){
		if(Type.numerico(p1) && Type.numerico(p2)) return p2;
		else if(p1 == Type.BOOL && p2 == Type.BOOL) return p2;
		else return null;
	}
	
	public void gen(int b, int a){
		emit( idVar.toString() + " = " + exprAtr.gen().toString() + ";" );
	}
}
